<?php

/**
 *      [品牌空间] (C)2001-2010 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: add_album.inc.php 5754 2011-10-27 06:10:34Z menglingmin $
 */

if(!defined('IN_ADMIN') && !defined('IN_STORE')) {
	exit('Acess Denied');
}

if(empty($_SGLOBAL['panelinfo']['enablealbum']) && !ckfounder($_G['uid']) && !permallow($_GET['action'],$_SGLOBAL['adminsession']['perms'])) {
	cpmsg('no_perm');
}

require_once(B_ROOT.'./source/adminfunc/album.func.php');

if(!empty($_POST['valuesubmit'])){
	if(intval($_POST['catid']) == "-1") {
		cpmsg('cat_null',$BASESCRIPT.'?action=add&m=album','error');
	}
	$albumid = createalbum($shopid, $_POST['catid'], $_G['uid'], $_G['username'], $_POST['album']['subject'], $_POST['album']['description'], $_POST['gosync']);

	if($albumid > 0) {
        if((!empty($_POST['syncfid']) || !empty($_SGLOBAL['panelinfo']['syncfid'])) && in_array($mname, $_SGLOBAL['panelinfo']['group']['synctypes']) && !empty($_POST['gosync'])) {
                            
            if($_SGLOBAL['panelinfo']['group']['maxnumsyncpreday'] > 0 && $_SGLOBAL['panelinfo']['lastsynctime'] == strtotime(sgmdate($_G['timestamp'], 'Ymd')) && $_SGLOBAL['panelinfo']['syncthisday'] >= $_SGLOBAL['panelinfo']['group']['maxnumsyncpreday']) {
                //do not syncpost
            } else{
                require_once(B_ROOT.'./api/bbs_syncpost.php');
                syncalbum($albumid);
            }
        }
	    itemnumreset('album', $shopid);
		$_BCACHE->deltype('sitelist', 'album');
		$_BCACHE->deltype('storelist', 'album', $shopid);
		$_BCACHE->deltype('storelist', 'photo', $shopid, $albumid);
		cpmsg('message_success', $BASESCRIPT.'?action=add&m=photo&albumid='.$albumid);
	}
}

//添加或更改的页面
shownav('infomanage', 'nav_album_add', $_SGLOBAL['panelinfo']['subject']);
showformheader('add&m=album');
showtableheader('');

showsetting('album_subject', 'album[subject]', '', 'text');
showsetting('album_description', 'album[description]', '', 'textarea');
$mycats = mymodelcategory('album');
$please_select = '<select name="album[catid]" id="album_catid" style="width:140px;"><option value="0" selected="selected">'.lang('please_select').'</option>';

foreach($mycats as $value) {
	$please_select .= '<option value="'.$value['catid'].'" >'.$value['name'].'</option>';
}
$please_select .= '</select>';
//showsetting('album_catid', 'album[catid]', '',$please_select);
echo '<tr><td class="td27" colspan="2">'.lang('shop_album_catid').'</td></tr><tr><td class="vtop rowform" id="'.$showarr['name'].'div" colspan="2">';
echo InteractionCategoryMenu(mymodelcategory('album'), 'catid', null, 1);
echo '</td></tr>';
	if((!$editvalue['itemid']) && $_SGLOBAL['panelinfo']['syncfid'] && in_array($mname, $_SGLOBAL['panelinfo']['group']['synctypes'])) {
		if($_SGLOBAL['panelinfo']['group']['maxnumsyncpreday'] > 0 && $_SGLOBAL['panelinfo']['lastsynctime'] == strtotime(sgmdate($_G['timestamp'], 'Ymd')) && $_SGLOBAL['panelinfo']['syncthisday'] >= $_SGLOBAL['panelinfo']['group']['maxnumsyncpreday']) {
			//do not sync
		} else {
			if($_SGLOBAL['panelinfo']['group']['maxnumsyncpreday'] == 0) {
				$moresyncinfo = '';
			} elseif($_SGLOBAL['panelinfo']['group']['maxnumsyncpreday'] > 0 && $_SGLOBAL['panelinfo']['lastsynctime'] == strtotime(sgmdate($_G['timestamp'], 'Ymd'))) {
				$moresyncinfo = $_SGLOBAL['panelinfo']['syncthisday'] .' / '. $_SGLOBAL['panelinfo']['group']['maxnumsyncpreday'];
			} elseif($_SGLOBAL['panelinfo']['group']['maxnumsyncpreday'] > 0 && $_SGLOBAL['panelinfo']['lastsynctime'] < strtotime(sgmdate($_G['timestamp'], 'Ymd'))) {
				$moresyncinfo = '0 / '.$_SGLOBAL['panelinfo']['group']['maxnumsyncpreday'];
			}
			echo '<tr><td colspan="2"><label><input type="checkbox" checked="checked" value="1" name="gosync">'.lang('gosync').' '.$moresyncinfo.'</label></td></tr>';
		}
	}

showalbumattr();

showsubmit('valuesubmit');
showtablefooter();
showformfooter();

?>
